package cn.com.demo.dao;

import cn.com.demo.entity.RolePermission;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RolePermissionDao extends BaseMapper<RolePermission> {
    /**
     * 获取用户角色
     * @param userId
     * @return
     */
    @Select({"SELECT ri.role_name FROM user_role ur INNER JOIN role_info ri ON ri.id = ur.role_id " +
            " WHERE ur.user_id = #{userId}"})
    List<String> getRuleByUserId(Integer userId);
    /**
     * 获取用户权限
     * @param userId
     * @return
     */
    @Select({"SELECT per.permiss_value FROM user_role ur INNER JOIN role_permission rp ON ur.role_id = rp.role_id" +
            " INNER JOIN permission_info per ON per.id = rp.per_id" +
            " WHERE ur.user_id = #{userId}"})
    List<String> getPermissByUserId(Integer userId);
}
